package com.lei.linearsearch;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/14 16:05
 * @Version 1.0
 */
public class Student implements Comparable<Student> {
    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (obj.getClass() != this.getClass()) return false;
        return this.name.equalsIgnoreCase(((Student) obj).name);

    }

    @Override
    public int compareTo(Student o) {
//        if (this.score < o.score) return -1;
//        else if (this.score == o.score) return 0;
//        return 1;
        return this.score - o.score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
